package com.infonova.product.jtf.blame.demo;

import java.util.HashMap;
import java.util.Map;


public class ServiceLocator {

    private Map<Class, Class> services = new HashMap<Class, Class>();

    public static ServiceLocator getInstance() {
        return new ServiceLocator();
    }

    private ServiceLocator() {
        services.put(Dao.class, DaoBean.class);
        services.put(Management.class, ManagementBean.class);
    }

    public <T> T getService(Class<T> clazz) {
        if (services.containsKey(clazz)) {
            try {
                return (T)services.get(clazz).newInstance();
            } catch (InstantiationException e) {
                return null;
            } catch (IllegalAccessException e) {
                return null;
            }
        }
        return null;
    }

}
